#include "cpu/exec/template-start.h"

#define instr shl

static void do_execute () {
	// DATA_TYPE src = op_src->val;
	// DATA_TYPE dest = op_dest->val;
	//提取src和dest的值
	DATA_TYPE src, dest;
	if(op_src->type == OP_TYPE_IMM){
		src = op_src->val;
	}
	else if (op_src->type == OP_TYPE_REG){
		switch (op_src->reg) {
			case 0: src = cpu.eax; break;
			case 1: src = cpu.ecx; break;
			case 2: src = cpu.edx; break;
			case 3: src = cpu.ebx; break;
			case 4: src = cpu.esp; break;
			case 5: src = cpu.ebp; break;
			case 6: src = cpu.esi; break;
			case 7: src = cpu.edi; break;
			default: Assert(0, "op_src->reg = %d", op_src->reg);
		}
	}
	else if (op_src->type == OP_TYPE_MEM){
		src = swaddr_read(op_src->addr, DATA_BYTE);
	}
	else{
		Assert(0, "op_src->type = %d", op_src->type);
	}
	if(op_dest->type == OP_TYPE_REG){
		switch (op_dest->reg) {
			case 0: dest = cpu.eax; break;
			case 1: dest = cpu.ecx; break;
			case 2: dest = cpu.edx; break;
			case 3: dest = cpu.ebx; break;
			case 4: dest = cpu.esp; break;
			case 5: dest = cpu.ebp; break;
			case 6: dest = cpu.esi; break;
			case 7: dest = cpu.edi; break;
			default: Assert(0, "op_dest->reg = %d", op_dest->reg);
		}
	}
	else if (op_dest->type == OP_TYPE_MEM){
		dest = swaddr_read(op_dest->addr, DATA_BYTE);
	}
	else{
		Assert(0, "op_dest->type = %d", op_dest->type);
	}
	//手动进行移位操作

	uint8_t count = src & 0x1f;
	dest <<= count;
	// OPERAND_W(op_dest, dest);
	//赋值
	if(op_dest->type == OP_TYPE_REG){
		switch (op_dest->reg) {
			case 0: cpu.eax = dest; break;
			case 1: cpu.ecx = dest; break;
			case 2: cpu.edx = dest; break;
			case 3: cpu.ebx = dest; break;
			case 4: cpu.esp = dest; break;
			case 5: cpu.ebp = dest; break;
			case 6: cpu.esi = dest; break;
			case 7: cpu.edi = dest; break;
			default: Assert(0, "op_dest->reg = %d", op_dest->reg);
		}
	}
	else if (op_dest->type == OP_TYPE_MEM){
		swaddr_write(op_dest->addr, DATA_BYTE, dest);
	}
	else{
		Assert(0, "op_dest->type = %d", op_dest->type);
	}
	//查看结果
	// Log("dest = %x", dest);

	update_eflags_pf_zf_sf(dest);

	print_asm_template2();
}

make_instr_helper(rm_1)
make_instr_helper(rm_cl)
make_instr_helper(rm_imm)

#include "cpu/exec/template-end.h"
